
import router from './router'
import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// const whiteList = ['/login'] // no redirect whitelist
const whiteList = ['/404', '/login']

router.beforeEach(async(to, from, next) => {
  NProgress.start()
  const token = store.getters.token

  if (token) {
    if (!store.getters.name) store.dispatch('user/getUserInfoActions')

    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      console.log('**********************')
      next()
    } else {
      next('/login')
    }
  }
})
// 全局后置守卫
router.afterEach(() => {
  NProgress.done()
})

